package com.oocl.aeat.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import com.oocl.aeat.dto.MerchantDto;
import com.oocl.aeat.redis.MerchantCache;
import com.oocl.aeat.util.IPUtil;
import com.oocl.aeat.util.JsonUtil;

/**
 * 对C端暴露的接口
 * 查询商家列表
 * @author GANAB
 *
 */
@WebServlet("/muser/all")
public class MUserServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private Logger logger = Logger.getLogger(MUserListServlet.class);

    public MUserServlet() {}

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setCharacterEncoding("utf-8");
    	PrintWriter out = response.getWriter();
    	String ip = IPUtil.getIpAddress(request);
    	List<MerchantDto> mdtolist = new ArrayList<MerchantDto>();
    	Map<String, MerchantDto> map = MerchantCache.getCache();
    	Set<String> keys = map.keySet();
    	for(String key : keys){
    		mdtolist.add(map.get(key));
    	}
    	out.write(JsonUtil.getJsonFromObject(mdtolist));
    	out.flush();
    	logger.info("ip="+ip+" query muser list.");
	}

}
